package com.eight.cloud.security.config;

import lombok.Data;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashSet;

/**
 * @ClassName: PermitProperties
 * @Author: TXC
 * @Date: 2024-10-15 11:02
 **/
@Data
@AutoConfiguration
@ConfigurationProperties("auth.config")
@RefreshScope
public class PermitProperties {
    private String[] commonIgnore = new String[] {};
    private String[] ignore = new String[] {};
    private boolean enable = true;

    public String[] getIgnore() {
        return getUnion(commonIgnore, ignore);
    }

    public static String[] getUnion(String[] array1, String[] array2) {
        HashSet<String> set = new HashSet<>(Arrays.asList(array1));
        set.addAll(Arrays.asList(array2));
        String[] union = new String[set.size()];
        int index = 0;
        for (String num : set) {
            union[index++] = num;
        }
        return union;
    }
}
